﻿#include "../head/Account.hh"
#include <iostream>
#include <sstream>
#include <iomanip>

Account::Account(std::string id, long long  init_balance, std::string holder) : accountId(id), balance(init_balance), accountHolder(holder) {}

Account::~Account() {}

bool Account::transfer(long long  amount, Account* destination, const std::string& note) {
    if (amount > 0 && balance >= amount && destination) {
        balance -=amount;
        destination->tranferfrom(amount, note,accountId);
        std::ostringstream oss;
        oss << "Transfer:    ￥" << std::setw(23) <<std::left<< tools::amountdisplay(amount) << " to   " << destination->getAccountId() << " Note: " << note;

        recordTransaction(oss.str());
        return 1;
    }
    else {
        return 0;
    }
}
void Account::tranferfrom(long long  amount, const std::string& note, std::string fromid)
{
    balance += amount;
    std::ostringstream oss;
    oss << "Transferred: ￥" << std::setw(20) << std::left << tools::amountdisplay(amount) << "    from " << fromid << " Note: " << note;
    recordTransaction(oss.str());
}
